package com.sinder.campus_prophet.web.general;

import com.sinder.campus_prophet.core.global.ResponseMessage;
import com.sinder.campus_prophet.service.general.TbWxUserService;
import com.sinder.campus_prophet.service.general.bean.dto.RegisterUserDto;
import com.sinder.campus_prophet.service.general.bean.dto.UpUserInfoDto;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;

/**
 * 通用接口集成
 * @author v-xyingde
 * @date 2023/3/20/17:23
 */
@RestController
@RequestMapping("general")
@Slf4j
public class GeneralApiController {
    private final TbWxUserService userService;

    public GeneralApiController(TbWxUserService userService) {
        this.userService = userService;
    }

    /**
     * 注册登记用户并返回用户信息
     * @param userDto
     * @return UserInfoVo
     */
    @PostMapping("registerUser")
    public ResponseMessage registerUser(@Validated @RequestBody RegisterUserDto userDto) {
        return userService.registerUser(userDto);
    }

    @GetMapping("getUserCode")
    public ResponseMessage getUserCode(@NotBlank(message = "用户标识不能为空") String openId) {
        return userService.getUserCode(openId);
    }

    @PostMapping("updateUserInfo")
    public ResponseMessage updateUserInfo(@Validated @RequestBody UpUserInfoDto userDto) {
        return userService.updateUserInfo(userDto)
                ? ResponseMessage.createBySuccessMessage("更新成功")
                : ResponseMessage.createByErrorMessage("更新异常");
    }

    @GetMapping("getUserInfo")
    public ResponseMessage getUserInfo(@NotBlank(message = "用户标识不能为空") String openId) {
        return userService.getUserInfo(openId);
    }
}
